
local actorpathwayPropertiesDialog = nil
local attachActorButton = nil
local playButton = nil

local function ShowActorPathwayProperties(userMessage)

	local callingEntity = userMessage:ReadEntity()
	local screenPos = callingEntity:GetPos():ToScreen()

	if(actorpathwayPropertiesDialog) then
		actorpathwayPropertiesDialog:SetVisible(true)
	else
		local PADDING = 7
		local ANCHOR_Y = PADDING
		actorpathwayPropertiesDialog = vgui.Create( "DFrame" ) 
		actorpathwayPropertiesDialog:SetPos( screenPos.x + 30,screenPos.y + 30) 
		actorpathwayPropertiesDialog:SetSize( (2 * PADDING) + 180, 300 ) 
		actorpathwayPropertiesDialog:SetTitle( "Properties")
		actorpathwayPropertiesDialog:SetVisible( true ) 
		actorpathwayPropertiesDialog:SetDraggable( false )
		actorpathwayPropertiesDialog:ShowCloseButton( false )
		actorpathwayPropertiesDialog:MakePopup() 
	    
		ANCHOR_Y = ANCHOR_Y + 20
		
		local propertiesLabel = vgui.Create("DLabel", actorpathwayPropertiesDialog) 
		propertiesLabel:SetText("Playback:") 
		propertiesLabel:SetTextColor(Color(255,255,255,255)) 
		propertiesLabel:SizeToContents()
		propertiesLabel:SetPos(PADDING,ANCHOR_Y)
		propertiesLabel.DoClick = function () 
			LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_LINKACTORCAMERAPATH)
			actorpathwayPropertiesDialog:SetVisible(false)
		end
		ANCHOR_Y = ANCHOR_Y + 20

		playButton = vgui.Create( "DButton" ) 
		playButton:SetParent( actorpathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
		playButton:SetText( "Play" ) 
		playButton:SetPos( PADDING, ANCHOR_Y) 
		playButton:SetSize( 180, 25 ) 
		ANCHOR_Y = ANCHOR_Y + 30

		local propertiesLabel = vgui.Create("DLabel", actorpathwayPropertiesDialog) 
		propertiesLabel:SetText("Create:") 
		propertiesLabel:SetTextColor(Color(255,255,255,255)) 
		propertiesLabel:SizeToContents()
		propertiesLabel:SetPos(PADDING,ANCHOR_Y)
		ANCHOR_Y = ANCHOR_Y + 20

		attachActorButton = vgui.Create( "DButton" ) 
		attachActorButton:SetParent( actorpathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
		attachActorButton:SetText( "Attach actor" ) 
		attachActorButton:SetPos( PADDING, ANCHOR_Y) 
		attachActorButton:SetSize( 180, 25 )
		ANCHOR_Y = ANCHOR_Y + 30

		local linkButton = vgui.Create( "DButton" ) 
		linkButton:SetParent( actorpathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
		linkButton:SetText( "Camera link" ) 
		linkButton:SetPos( PADDING, ANCHOR_Y) 
		linkButton:SetSize( 180, 25 ) 
		linkButton.DoClick = function () 
			LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_LINKACTORCAMERAPATH)
			actorpathwayPropertiesDialog:SetVisible(false)
		end
		ANCHOR_Y = ANCHOR_Y + 30
		
		local propertiesLabel = vgui.Create("DLabel", actorpathwayPropertiesDialog) 
		propertiesLabel:SetText("Parameters:") 
		propertiesLabel:SetTextColor(Color(255,255,255,255)) 
		propertiesLabel:SizeToContents()
		propertiesLabel:SetPos(PADDING,ANCHOR_Y)
		ANCHOR_Y = ANCHOR_Y + 20

		local trackName = vgui.Create( "DTextEntry" ) 
		trackName:SetParent( actorpathwayPropertiesDialog ) // Set parent to our "DermaPanel" 

	   if CatmullRomCams.SToolMethods.ActorMover.IsPathNode( callingEntity ) then
			trackName:SetText( callingEntity.BaseClass.GetTrackIndex(callingEntity)) 
	   else
			trackName:SetText( "Error" ) 
	   end
		
		trackName:SetPos( PADDING, ANCHOR_Y) 
		trackName:SetSize( 180, 25 ) 
		trackName.OnEnter = function () 
			toolState = TOOLSTATE_IDLE
			npc_doNotify("TODO: implement naming", "NOTIFY_ERROR", LocalPlayer())
			actorpathwayPropertiesDialog:SetVisible(false)
		end
		ANCHOR_Y = ANCHOR_Y + 30

		local animationButton = vgui.Create( "DButton" ) 
		animationButton:SetParent( actorpathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
		animationButton:SetText( "Animation" ) 
		animationButton:SetPos( PADDING, ANCHOR_Y) 
		animationButton:SetSize( 180, 25 ) 
		animationButton.DoClick = function () 
			toolState = TOOLSTATE_IDLE
			local toolState = self:GetClientNumber("toolstate")
			actorpathwayPropertiesDialog:SetVisible(false)
		end
		ANCHOR_Y = ANCHOR_Y + 30
		
		local okButton = vgui.Create( "DButton" ) 
		okButton:SetParent( actorpathwayPropertiesDialog ) // Set parent to our "DermaPanel" 
		okButton:SetText( "Close" ) 
		okButton:SetPos( PADDING, ANCHOR_Y) 
		okButton:SetSize( 180, 25 ) 
		okButton.DoClick = function () 

			actorpathwayPropertiesDialog:SetVisible(false)
		end  
	end   

	if playButton then
		playButton.DoClick = function () 
			LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_PLAYACTORS)
			LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
			actorpathwayPropertiesDialog:SetVisible(false)
		end
	end

	if attachActorButton then
		attachActorButton.DoClick = function () 
			if CatmullRomCams.SToolMethods.ActorMover.IsPathNode(callingEntity) then
				LocalPlayer():ConCommand( "npc_mover_gun_entitIDfromclient " .. callingEntity:EntIndex())
				LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_LINKACTORTOPATH)
			else
				PrintError(7)
				selectedNPCPathNode = nil
				LocalPlayer():ConCommand( "npc_mover_gun_toolstate " .. CatmullRomCams.SToolMethods.ActorMover.TOOLSTATE_IDLE)
			end
			actorpathwayPropertiesDialog:SetVisible(false)
		end
	end
end

usermessage.Hook( "ShowProperties" .. "sent_pathnode", ShowActorPathwayProperties) 
